<script type="text/javascript">
	/* 获取彩种下注区 */
	function xiazhu(){
		if($("#cname").text() == 'bjl'){
			return;
		}
		$.ajax({
			url: "/lotter/lots.do",
			type: "post",
			data: {
				cname: $("#cname").text(),
			},
			success:function(data){
				console.log(data,"我拿到的值");
				if(data == 50) {
					save.push("sy");
					bindSetData("login");
					return;
	   			}else if(data==60){
					pagePreserve();
					return;
				}
				$(".xiazhu").html();
				$(".xiazhu").html(data.data);
			}
		});   
	}
	xiazhu(); 
	var only = true;
	var unique = true;
	/* 一进来拿的数据 */
	$.ajax({
		url: "/order/lotterData.do",
		type: "post",
		data: {
			/* period: $(".class-div-qiuGroups .xiaqi").text(), */
			cname: $("#cname").text(),
			type:1,
		},
		success:function(data){
			console.log(data);
			if(data == 50) {
				save.push("sy");
				bindSetData("login");
				return;
   			}else if(data==60){
				pagePreserve();
				return;
			}
			var cname=$("#cname").text();
			$("#span-i-xiazhuzonge").text(data.data);  /* 当期下注总额 */
			$("#balance").text(data.data1);  /* 用户余额 */
			/* 拿球数的限制 */
			if(data.data3!=''){
				if (cname == "xg6hc" || cname == "5f6hc") {
					QIU_PICK_CONTROL[cname](data.data3)
				} else {
					QIU_PICK_CONTROL[cname](data.data3[0].kongzhisl)
				}
			}else{
				if(cname!='bjl'){
					QIU_PICK_CONTROL[cname]()
				}
			}
			/* if(data.data2!=''){
				setSlideData(data.data2)  展示用户下注信息  暂时注释掉后面可能会用
			} */
		}
	});
	
	/* 拿选择下注的金额 */
	$.ajax({
		url: "/title.do",
		type: "post",
		data: {},
		success:function(data){
			console.log(data);
			for(i=0;i<5;i++){
				$("#kuaisuxuanze button").eq(i).text(data.data["buy"+(i+1)]);
			}
		}
	});
	
	/* 当期下注总额 */
 	var setXianZhuZongE = function() {
	 	var urlPath = "/order/orderSum.do";
			var newRequest = {
				url: urlPath,
				type: "post",
				data: {
					period: $(".class-div-qiuGroups .xiaqi").text(),
					cname: $("#cname").text(),
				},
				success: function(data) {
					if(data == 50) {
						save.push("sy");
						bindSetData("login");
						return;
		   			}else if(data==60){
						pagePreserve();
						return;
					}
					$("#span-i-xiazhuzonge").text(data.data);
				},
			};
			$.ajax(newRequest);
	}; 
	var daojishi = 0;  /* 倒计时时间 */
	caizhong_cname=$("#cname").text();
	$("html").css("height","100%");
	$("body").css("height","100%");
	$("#xfm").css("height","100%");
	$(".foot").hide();
	var state = false;
	
	/* 点击选择功能 */
	$("#id-ul-xiaLaMenu li").on("click",function(){
		if($(this).hasClass("zs")){
			localStorage.setItem("lottername",$("#cname1").text());
		}
		if($(this).hasClass("exit")){
			$.ajax({
				url:'/exit.do',
				type:'post',
				data:{},
				success:function(){
				page="sy";
				save.push("sy");
				$(".foot").show();
				bindSetData('login');
				$("html").css("font-size","12px");
				},
			});
		}
	});
		DaoJiShiTask();
		function DaoJiShiTask(){
			$("#fenpan").removeClass("hidden");
			/* 加锁 */
			if(only){
				only=false;
				timer = setInterval(DaoJiShi, 1000);
			}
			/* 倒计时时间 */
			var a = 4;
			/* 通过倒计时显示时间并判断是否封盘 */
			 function DaoJiShi(){
			 if($("#id-div-headerNav").length==0){
				 only=true;
				 clearInterval(timer);
				 return;
			 }
				 daojishi--;
			 	var h = parseInt(daojishi/ 60 / 60 % 60);
			    var m = parseInt(daojishi/ 60 % 60);
			 	var s = parseInt(daojishi% 60);
			 	if(h <= 0 && m <= 0 && s <= 0){
				 	$("#djs").text("00:00:00");
			 		state = true;
				}else{
						if(h < 10){
							h = "0"+h;
						}
						if(m < 10){
							m = "0"+m;
						}
						if(s < 10){
							s = "0"+s;
						}
						$("#djs").text(h+":"+m+":"+s);
				}
			 	/*  */
			 	if(h <= 0 && m <= 0 && s <= 30){
			 		$("#fenpan").removeClass("hidden");
			 	}else{
			 		$("#fenpan").addClass("hidden");
			 	}
			 	if(state || $("#cname").text() == 'xg6hc' ){
			 		a++;
			 		if(a >= 4){
			 			a = 0;
				 		$.ajax({
							url: "/findNextNextPeriod.do",
							type: "post",
							data: {
								"cname":$("#cname").text(),
								"type":1
							},
							success: function(data) {
								if(data == 50) {
									save.push("sy");
									bindSetData("login");
									return;
		   						}
							if(data.data != null){
							var fnextPeriod = data.data.nextperiod;
								var nextPeriod = $(".xiaqi").text();
								if(fnextPeriod >= nextPeriod){
									$(".xiaqi").text(fnextPeriod);
									$(".period").text(data.data.period);
									var curTime=new Date(data.message).getTime(); 
									var nextTime=new Date(data.data.nextStopOrderTimeEpoch).getTime();
									daojishi =(nextTime-curTime)/1000; 
								}
								if($(".period").text() == data.data.period){
									var haoma="";
									var lotterNumber =  data.data.lotternumber;
									if(lotterNumber==null){
										lotterNumber = "";
									}
									lotterNumber1=lotterNumber.split(",");
									if(lotterNumber1.length > 1){
										$(".lotternumber").text(lotterNumber);
										 qiu();
										state = false;
									}else{
										$(".lotternumber").html("<span style='margin:1px;color:white;width:0.46rem;height:0.46rem;line-height:0.46rem;font-size:0.33rem;display:inline-block;' class='text-center yuan qiu8'>正</span><span style='margin:1px;color:white;width:0.46rem;height:0.46rem;line-height:0.46rem;font-size:0.33rem;display:inline-block;' class='text-center yuan qiu8'>在</span><span style='margin:1px;color:white;width:0.46rem;height:0.46rem;line-height:0.46rem;font-size:0.33rem;display:inline-block;' class='text-center yuan qiu8'>开</span><span style='margin:1px;color:white;width:0.46rem;height:0.46rem;line-height:0.46rem;font-size:0.33rem;display:inline-block;' class='text-center yuan qiu8'>奖</span>");
									}
								}
							}
							},
						});
			 		}
			 	}
			};
		};
	
		/* 快速选择 */
	$("#kuaisuxuanze button").on("click",function(){
		$("#dzje").val($(this).text());
		gongji();
	});
		/* 获取单注金额焦点时出现快速选择金额 */
	$("#dzje").on("focus",function(){
		$("#div-i-footer-hemai").css("bottom","40px");
		$("#kuaisuxuanze").removeClass("hidden");
	});
		
		/* 不点击单注金额时快速金额不显示 */
	$("*").not("#dzje").on("click",function(){
		$("#div-i-footer-hemai").css("bottom","0");
		$("#kuaisuxuanze").addClass("hidden");
	});
	var ZONGZHUSHU = 0;  /* 总注数 */
	
	/* 失去焦点时显示共计 */
	$("#dzje").on("blur",function(){
		gongji();
	});
	
	/* 算出共计多少元 */
	function gongji(){
		ZONGZHUSHU=Number($("#dzje").val().trim())*Number($("#zhushu").text());
		$("#gongji").text(ZONGZHUSHU); 
	};
	
	
var ALL_TIME;	
var TIME_EVENT_ID;
var IS_TIME_CURRENT;
var SPECIAL_CAIZHONG = ["bjpk10", "2fpk10"];
var NOT_STOP = ["2fpk10", "2fssc", "xysm", "3fk3"];
var ISFIRSTLOTTER_flag = true;
var MONEY_FROM_SERVER = "";
var COUNT_FROM_SERVER = 0;
var isNeedFengPan = true;
var COLOR_OBJECT = {
		"1": "qiu1",
		"2": "qiu2",
		"3": "qiu3",
		"4": "qiu4",
		"5": "qiu5",
		"6": "qiu6",
		"7": "qiu7",
		"8": "qiu8",
		"9": "qiu9",
		"10":  "qiu10"
};
	function cancel(){$(".zdsd").addClass("hidden");$("#checkboxhm").removeAttr("checked");};
	
	/* 重置 */
		function clear1() {
			ZHUSHU = 0;
			$(".act").removeClass("act");
			$(".wfdiv input").val("");
			$("#zhushu").text("0");
			$("#gongji").text("0");
		};
		
		
		function submit(){
			$(".zdsd").addClass("hidden");
		};
		
		
		var confirmXiaZhu = function(rebate, testState, slv) {
			var odd = 1;
			var ajaxData = {
				url: '/order/awards.do',
				type: "post",
				data: {
					lotterid: $("#id").text(),
					cname: $("#cname").text(),
					cname1: $("#cname1").text(),
					period: Number($(".xiaqi").text()),
					lottermoney:$("#dzje").val(),		
					odds:odd
				},
				success: function(data) {
					var mess = data.message;
					if(data.state==1){
						if(mess=='0'){
							showNormalNoticeModal("#div-i-noticeGenDan", "提示：", data.data); 
							/* $("#checkboxhm").prop("checked", false);
							$("#checkboxgd").prop("checked", false); */
							XIAZHU_BTN_LOCK = true;
							return;
						}
						if (data.data === 10) {
							showNormalNoticeModal("#div-i-noticeGenDan", "提示：", mess);
							/* $("#checkboxhm").prop("checked", false);
							$("#checkboxgd").prop("checked", false); */
							XIAZHU_BTN_LOCK = true;
							return;
						}
							$("#balance").text("￥"+ new Number(data.message));
							var parentUl = document.querySelector(".ul-c-betSuccessItem");
							var wanfaHTML = "";
							for (var i = 1; i <= 40; i++) {
								var item = data.data["cplay" + i];
								if (item != null) {
									var value = "<td>" + data.data["cplay" + i] + "</td><td>" + data.data["str" + i] + "</td>";
									value = "<tr>" + value + "</tr>";
									wanfaHTML += value;
								}
							}
							var shouyizhi = (Number(data.data.lottermoney) * Number(MONEY_FROM_SERVER)).toFixed(2);
							parentUl.innerHTML = "<tr><td>投注期号</td><td><span style='color:black;font-weight:bold;'>" + data.data.period + "</span></td></tr>" + 
							"<tr><td>投注注数</td><td><span style='color:red;font-weight:bold;'>" + COUNT_FROM_SERVER + " 注</span></td></tr>"+
							"<tr><td>投注金额</td><td><span style='color:red;font-weight:bold;'>" + ZONGZHUSHU + " 元</span></td></tr>"+
							"<tr><td>预估收益值</td><td><span style='color:red;font-weight:bold;'> " + shouyizhi + " 元</span></td></tr>"+
							"<tr class='wanfa-li-special'><td style='font-weight:bold;'>玩法</td><td style='font-weight:bold;'>投注号码</td></tr>"+ wanfaHTML;
							var orderId = data.data.id;
							/* 拿开奖号 */
						 	$.ajax({
								url: "/findNextNextPeriod.do",
								type: "post",
								data: {
									"cname":$("#cname").text(),
									"type":1
								},
								success: function(data) {
									var fnextPeriod = data.data.nextperiod;
									var nextPeriod = $(".xiaqi").text();
									if($(".period").text() == data.data.period){
										var haoma="";
										var lotterNumber =  data.data.lotternumber;
										if(lotterNumber==null){
											lotterNumber = "";
										}
										lotterNumber1=lotterNumber.split(",");
										if(lotterNumber1.length > 1){
											$(".lotternumber").text(lotterNumber);
											 qiu();
										}else{
											$(".lotternumber").html("<span style='margin:1px;color:white;width:0.46rem;height:0.46rem;line-height:0.46rem;font-size:0.33rem;display:inline-block;' class='text-center yuan qiu8'>正</span><span style='margin:1px;color:white;width:0.46rem;height:0.46rem;line-height:0.46rem;font-size:0.33rem;display:inline-block;' class='text-center yuan qiu8'>在</span><span style='margin:1px;color:white;width:0.46rem;height:0.46rem;line-height:0.46rem;font-size:0.33rem;display:inline-block;' class='text-center yuan qiu8'>开</span><span style='margin:1px;color:white;width:0.46rem;height:0.46rem;line-height:0.46rem;font-size:0.33rem;display:inline-block;' class='text-center yuan qiu8'>奖</span>");
										}
									}
								}
							});
								$("#betSuccessModal .modal-title").text("下注成功!");
								XIAZHU_BTN_LOCK = true;
								$("#betSuccessModal").modal("show");
								$('.modal-backdrop').removeClass('in');
								setXianZhuZongE();
							XIAZHU_BTN_LOCK = true;
							clear1();
					}
				},
			};		
			setAllActItem(ajaxData.data);
			$.ajax(ajaxData);			
		};
		
		var XIAZHU_BTN_LOCK = true;
		
		function comit() {
			if (!XIAZHU_BTN_LOCK) {
				return;
			}
			XIAZHU_BTN_LOCK = false;
			if (!checkValueIsNumber($("#dzje").val())) {
				showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "无效的单注金额");
				XIAZHU_BTN_LOCK = true;
				return;
			}
			if ($(".act").length === 0) {
				showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "请先选择下注号码");
				XIAZHU_BTN_LOCK = true;
				return;				
			}
			if ($("#cname").text() != "xg6hc") {
				if (FAKE_ZHUSHU != 0){
					if ($("#checkboxgd").is(':checked'))  {
						$.ajax({
							url:'/order/getTestState.do',
							type:'post',
							data:{},
							success:function(data){
								if(data == 50) {
									save.push("sy");
									bindSetData("login");
									return;
		   						}
								var dataArray = data.message.split(",");
								confirmXiaZhu(dataArray[0], data.data, dataArray[1]);
								XIAZHU_BTN_LOCK = true;
							},
						})
					} else {
						confirmXiaZhu();
					}				
				}
				else{
					showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "请选择正确的号码");
					XIAZHU_BTN_LOCK = true;
				}
			} else {
				$.ajax({
					url:'/lotter/xglhc.do',
					type:'post',
					data: {
						cname: "xg6hc",
						xg6hc: "",
						},
					success:function(data){
						var lastObj = data.data;
						ajax({
							url: '/lotter/xglhc.do',
							type:'post',
							data: {
								cname: "xg6hc",
								xg6hc: lastObj.xg6hcstate + 1,
								},
							success:function(data){
								if(data == 50) {
									save.push("sy");
									bindSetData("login");
									return;
		   						}
								var newData = JSON.parse(data);
								var nextObj = newData.data;
								var nowTime = transDateLetter(newData.message);
								var nextTime = transDateLetter(nextObj.nextStopOrderTimeEpoch);		
								var chazhiValue = Math.floor(new Date(nextTime).getTime() / 1000) - Math.floor(new Date(nowTime).getTime() / 1000);			
					 			/* 一直没有派奖，现在正在开奖 */
								if (nextObj.touzhuzt === null && chazhiValue <= 0) {
									showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "已经封盘，无法进行下注操作");
									XIAZHU_BTN_LOCK = true;
									return;									
								}
								/*  一直没有派奖，显示倒计时 */
								else if(nextObj.touzhuzt === null && chazhiValue <= 30) {
									showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "已经封盘，无法进行下注操作");
									XIAZHU_BTN_LOCK = true;
									return;									
								}
								/*   nextObj.touzhuzt != null, 直接显示*/
								else if (nextObj.touzhuzt != null) {
									showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "已经封盘，无法进行下注操作");
									XIAZHU_BTN_LOCK = true;
									return;
								}
							    if (FAKE_ZHUSHU != 0){
									if ($("#checkboxgd").is(':checked'))  {
										$.ajax({
											url:'/order/getTestState.do',
											type:'post',
											data:{},
											success:function(data){
												if(data == 50) {
													save.push("sy");
													bindSetData("login");
													return;
		   										}
												var dataArray = data.message.split(",");
												confirmXiaZhu(dataArray[0], data.data, dataArray[1]);
												XIAZHU_BTN_LOCK = true;
											},
										})
									} else {
										confirmXiaZhu();
									}				
								}	
							},
							error: function(error) {
								showNormalNoticeModal("#div-i-noticeGenDan", "提示：", "网络繁忙");
								XIAZHU_BTN_LOCK = true;
							}							
						});							
					},
				})
			}
		}
		bindAllCloseFakeModalBtns();
		
		function help(url, str) {
			document.write("<form action=/help.do method=post name=form1 style='display:none'>");
			document.write("<input type=hidden name=url value='" + url + "'/>");
			document.write("<input type=hidden name=str value='" + str + "'/>");
			document.write("</form>");
			document.form1.submit();
		}
		$(function(){
			/* 点击显示隐藏功能菜单 */
			$(".user").click(function(){
				if($(".nav").attr("class").indexOf("hidden")!=-1){
					$(".nav").removeClass("hidden");
				}else{
					$(".nav").addClass("hidden");
				}
			});
			/* 切换玩法 */
			$(".wf a").click(function(){
				$(".acti").removeClass("acti");
				$(this).addClass("acti");
			});
		});
 			var insertNewData = function(arr) {
				var div = document.querySelector(".modal-body");
				var currentCName = $("#cname").text();
				div.innerHTML = "";
				for (var i = 0; i < arr.length; i++) {
					var item = arr[i];
					var spanHTML = "";
					if (item.lotternumber.indexOf(",") === -1) {
						spanHTML = item.lotternumber;
					} else {
						var spanArray = item.lotternumber.slice(0, item.lotternumber.length - 1);
						spanArray = spanArray.split(",");
						for (var j = 0; j < spanArray.length; j++) {
							var spanItem = spanArray[j];
							var specialClass = "";
							var xg6hcBackGround = "";
							if (SPECIAL_CAIZHONG.indexOf(currentCName) != -1) {
								specialClass = COLOR_OBJECT[j + 1];
							}
							if (currentCName === "xg6hc") {
								if (blueArr.indexOf(spanItem) != -1) {
									xg6hcBackGround = "style='background-color:#336DCC;'";
								}
								else if (greenArr.indexOf(spanItem) != -1) {
									xg6hcBackGround = "style='background-color:#09B832;'";
								}								
							}
							var html = "<span class='span-item-circle " + specialClass + "' " + xg6hcBackGround + ">" + spanItem + "</span>";
							if (j === spanArray.length - 1 && currentCName === "xg6hc") {
								html = "<span style='display:inline-flex;margin:1px;color:black;font-size:0.33rem;width:0.46rem;height:0.46rem;justify-content:center;align-items:center;max-width:26px;max-height:26px;'>+</span>" + html;
							}
							if (j === spanArray.length - 1 && currentCName === "5f6hc") {
								html = "<span style='display:inline-flex;margin:1px;color:black;font-size:0.33rem;width:0.46rem;height:0.46rem;justify-content:center;align-items:center;max-width:26px;max-height:26px;'>+</span>" + html;
							}
							spanHTML += html;
						}
					}
					var html = "<div class='green'>"+
					"期号：<span>" + item.period + "</span><br>"+
					"奖号：" + spanHTML + "<br>"+
					"日期：<span>" + item.paijtime + "</span>"+
				"</div>";
					div.insertAdjacentHTML("beforeend", html);
				}
			};
		var timerId = null ;
		var interval = null;

		/* 单注金额获取焦点 */
		$("#dzje").focus(function(event) {
		var explorer = navigator.userAgent;
		if(explorer.indexOf("UCBrowser") >= 0){
			var cnt = 0;
			timerId = setInterval( function() {
		if($("#id-div-headerNav").length==0){
			clearInterval(timerId);
		}
			    if (cnt < 3) {
			      cnt++;
			    } else {
			      clearInterval(timerId);
			      timerId = null;
			      return;
			    }
			   document.body.scrollTop = document.body.scrollHeight;
		  }, 300)				
		}		
	});	
		
		/* 失去焦点 */
	$("#dzje").on("blur", function(event) {
	    if (timerId) {
		    clearInterval(timerId);
		    timerId = null;
		}
	    if (interval) {
			clearInterval(interval);
	    }
	});
		/* 点击走势图 */
	$("#a-i-zoushitu").on(getEndClickEvent(), function() {
		var lotterName = "${lotter.cname }";
		if (lotterName == "gdkl10f" || lotterName == "cqkl10f") {
			alertme("快乐十分暂无走势图");
		} 
		else if (lotterName == "xg6hc") {
			alertme("香港六合彩暂无走势图");
		}
		else {
		}
	});
	var better;

	/* 每秒更新下注总额 */
	function autoUpDateXianShuZongE() {
		better= setInterval(function() {
		if($("#id-div-headerNav").length==0){
			clearInterval(better);
		}
			setXianZhuZongE();
		}, 1000);
	};
	$(".xiazhu").css("max-width", String($(".class-div-contentDiv").width() - 50) + "px");
		$(".class-div-contentDiv").css("margin-top", "130px");
		jianrong();	
		qiu();
</script>
